<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加奖品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/static/admin/plugins/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/static/admin/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/webupload/xb-webuploader.css">
    <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
</head>

<body>
<div style="margin: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>添加奖品</legend>
    </fieldset>

    <form class="layui-form" style="width:1000px;" action="/prize/add" id="addForm">
        <div class="layui-form-item">
            <label class="layui-form-label">关联活动</label>
            <div class="layui-input-block">
                <select name="aid" lay-verify="required" lay-search>
                    <option value="">请选择关联活动</option>
                    {foreach name="activity" item="val" key="key"}
                        <option value="{$val.id}" {if condition="$val['id'] eq $aid"}selected{/if}>{$val.title}</option>
                    {/foreach}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="rank_name" lay-verify="required" autocomplete="off" placeholder="请输入名称" class="layui-input" maxlength="20">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="sort" lay-verify="required" autocomplete="off" placeholder="排序" class="layui-input" maxlength="20">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">名次区间</label>
            <div class="layui-input-block">
                <div class="layui-input-inline min-width">
                    <input name="min_rank"  lay-verify="required" autocomplete="off" class="layui-input" type="text">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline min-width">
                    <input name="max_rank"  lay-verify="required"  autocomplete="off" class="layui-input" type="text">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">奖品</label>
            <div class="layui-input-block">
                <input type="text" name="prize" lay-verify="required" autocomplete="off" placeholder="请输入奖品" class="layui-input" maxlength="20">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">奖品图片</label>
            <div class="layui-input-block">
                <input type="hidden" name="poster" id="logo" autocomplete="off" class="layui-input">
                <div id="logo_upload" class="wu-example logo">
                    <div class="uploader-list logo">
                    </div>
                    <div class="webuploader-container logo" >
                        <div class="webuploader-pick">选择图片</div>
                    </div>
                    <div class="fileMsg logo"></div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">说明</label>
            <div class="layui-input-block long">
                <textarea id="editor" name="content" lay-verify="required" style="padding: 0;margin:0;" class="layui-textarea"></textarea>
                <script src="/static/uedit/ueditor.config.js"></script>
                <script src="/static/uedit/ueditor.all.min.js"></script>
                <script>
                    var ue = UE.getEditor('editor');
                    function edit() {
                        $("textarea[name=content]").val(ue.getContent());
                    }
                </script>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo">立即提交</button>
                <a class="layui-btn layui-btn-primary" href="/prize/index">奖品列表</a>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="/static/admin/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/static/webupload/webuploader.min.js"></script>
<script type="text/javascript" src="/static/webupload/webuploader-one.js"></script>
<script type="text/javascript" src="/static/webupload/webuploader-set.js"></script>
<style>
    .layui-input-block{
        width: 500px;
    }
    .layui-input-block.long{
        width: 70%;
    }

    .wu-example.logo{
        height:100px;
    }
    .webuploader-container.logo{
        width:76px;
        height:43px;
        float: left;
    }
    .uploader-list.logo{
        width:100px;
        height:100px;
        float: left;
        margin-left:5px;
    }
    .uploader-list img{
        height:100px;
    }
    .fileMsg.logo{
        float: left;
    }

</style>
<script>

    layui.use(['form'], function () {
        var form = layui.form(),
            layer = layui.layer;

        uploadOne('#logo_upload', '#logo', WebUploader, '#logoImg');

        //监听提交
        form.on('submit(demo)', function(data) {
            var url = $(data.form).attr('action');
            $.ajax({
                type: "POST",
                url: url,
                data:  data.field,
                async: true,
                beforeSend: function () {
                    jz = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
                },
                error: function (request) {
                    layer.close(jz);
                    layer.alert('网络错误',{icon:2}, function(index){
                        layer.close(index);
                    });
                },
                success: function (data) {
                    //关闭加载层
                    layer.close(jz);
                    if (data.code == 1) {
                        layer.msg(data.msg, {
                            icon: 1,
                            time: 1500
                        }, function(){
                            window.location.href = data.data.url;
                        });
                    } else if(data.code == -1){
                        window.location.href = '/login/login';
                    }else {
                        layer.alert(data.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>

</html>
